package com.zx.mes.weather.hyl.feign.impl;

import com.zx.mes.weather.hyl.entity.WeatherResponse;
import com.zx.mes.weather.hyl.feign.WeatherDataFeignClient;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * WeatherDataFeignClient 快速失败接口实现
 * @author hyl
 * @date 2018-3-6
 */
@Component
public class WeatherDataFeignClientFallbackFactory implements FallbackFactory<WeatherDataFeignClient>{

    private static final Logger logger = LoggerFactory.getLogger(WeatherDataFeignClientFallbackFactory.class);

    @Override
    public WeatherDataFeignClient create(Throwable cause) {
        return (String cityName) -> {
            WeatherResponse weatherResponse=new WeatherResponse();
            weatherResponse.setStatus("500");
            weatherResponse.setMessage("请稍等几分钟再访问!");
            logger.info("快速失败原因:{},传参:[cityName]{}",cause.getMessage(),cityName);
            return weatherResponse;
        };
    }
}
